package cn.detu.ln.controller;

import cn.detu.ln.entity.Motive;
import cn.detu.ln.service.MotiveService;
import cn.detu.ln.utils.PageUtil;
import cn.detu.ln.utils.RestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("motive")
public class MotiveController {
    @Autowired
    private MotiveService motiveService;
    @GetMapping("{url}")
    public RestUtil userGet(@PathVariable String url, Motive motive, PageUtil pageUtil, String search){
        switch (url){
            case "selectAll": return motiveService.selectAll();
            case "motiveDelete":return motiveService.motiveDelete(motive.getMotiveId());
            // 通过课程名称模糊查询学力值
            case "queryMotiveByPage":return motiveService.queryMotiveByPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    search);
            // 通过学号模糊查询学力值
            case "queryMotiveByStuNumPage":return motiveService.queryMotiveByStuNumPage(pageUtil.getCurrent(),pageUtil.getRows(),
                    motive.getStuNum());
            // 学号 + 课程名称
            case "queryMotiveByStuCouNamePage":return motiveService.queryMotiveByStuCouNamePage(pageUtil.getCurrent()
                    ,pageUtil.getRows(),motive.getStuNum(),search);
            // 学号 + 周数
            case "queryMotiveByStuWeekPage":return motiveService.queryMotiveByStuWeekPage(pageUtil.getCurrent(),
                    pageUtil.getRows(),motive.getStuNum(),search);
        }

        return null;
    }
    @PostMapping("{url}")
    public RestUtil userPost(@PathVariable String url, Motive motive){
        switch (url){
            case "motiveUpdate":return motiveService.motiveUpdate(motive);
            case "motiveInsert":return motiveService.motiveInsert(motive);
        }
        return null;
    }
}
